package cn.com.czpb.client.module.news.view;

import android.app.Activity;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.nanning.FuWuBean;
import cn.com.czpb.client.module.nanning.adapter.NanningTopViewAdapter;

import java.util.List;

import cn.com.czpb.client.utils.PageCtrl;

/**
 * Created by 猪猪侠 on 2017/7/25.
 */

public class TopViewNanning  {
    private View rootView;
    private Activity mActivity;
    private Handler viewHandler = new Handler();

    private HorizontalListView horizontalListView;
    private ImageView topnanningmore;
    private List<FuWuBean> list;
    private NanningTopViewAdapter topadapter;
    public static TopViewNanning instance(Activity activity,List<FuWuBean> list){

        return new TopViewNanning(activity,list);
    }

    public TopViewNanning(Activity activity,List<FuWuBean> list){
        //
        this.list = list;
        this.mActivity = activity;
        initView(activity);
    }

    public View getView(){
        return rootView;
    }
    /**
     * @param context
     */
    private void initView(Activity context) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        rootView = layoutInflater.inflate(R.layout.view_nanning,null);
        horizontalListView = rootView.findViewById(R.id.city_horizontallv);
        topnanningmore = rootView.findViewById(R.id.top_view_nanning_more);
        topadapter = new NanningTopViewAdapter(mActivity,list);
        horizontalListView.setAdapter(topadapter);
        horizontalListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PageCtrl.start2FuWuDetialActivity(mActivity,list.get(position).getLink());
            }
        });
        viewHandler.removeCallbacksAndMessages(null);
    }
    public void refreshData(List<FuWuBean> list){
        this.list.clear();
        this.list.addAll(list);
        topadapter.notifyDataSetChanged();
    }
}
